import collections
class Solution(object):
    def findSubstringInWraproundString(self, p):
        """
        :type p: str
        :rtype: int
        """
        d = collections.defaultdict(int)
        count = 1
        right = 1
        n = len(p)
        d[p[0]] = 1
        while right < n:
            if ord(p[right]) - ord(p[right - 1]) == 1 or ord(p[right]) - ord(p[right - 1]) + 26 == 1:
                count += 1
                d[p[right]] = max(count, d[p[right]])
            else:
                count = 1
                d[p[right]] = max(count, d[p[right]])
            right += 1
        total = 0
        for key in d:
            total += d[key]
        return total


